package com.fangdada.demoreactor8.reactor8;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @Author: fd
 * @Date 2021/11/29 15:16
 * @Description: Reactor实现响应式编程
 */
public class ReactorDemo {

	public static void main(String[] args) {
		// Flux just 方法直接声明
		Flux<Integer> just = Flux.just(1, 2, 3, 4);
		// 订阅才会输出
		System.out.print("测试Flux just 方法直接声明:");
		just.subscribe(System.out::println);
		// Mono just 方法直接声明
		Mono<String> integerMono = Mono.just("测试Mono");
		// 订阅才会输出
		integerMono.subscribe(System.out::println);

		//其他的方法
		System.out.print("测试Flux fromArray 方法");
		Integer[] array = {5,6,7,8};
		Flux.fromArray(array).subscribe(System.out::println);

		System.out.print("测试Flux fromIterable 方法");
		List<Integer> list = Arrays.asList(array);
		Flux.fromIterable(list).subscribe(System.out::println);

		System.out.print("测试Flux fromStream 方法");
		Stream<Integer> stream = list.stream();
		Flux.fromStream(stream).subscribe(System.out::println);
	}

}
